<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >

<head>
    <meta charset="UTF-8">
    <title>验收相关方签名</title>
    <script src="{% static 'front/jquery-3.6.0.min.js' %}"></script>
</head>

<body onresize="hero();">

  <object id="HWPenSign"
    name="HWPenSign"
    classid="clsid:A0637EB8-68DB-4cf0-A26C-1CA438E1D6D1"
    width="600"
    height="300"
    >
  </object>
    
  <div style="margin-left: 33%; margin-top: 10px">
    <!--<input id="BTInit" type="button" value="??ʼ?????" onclick="return BTInit_onclick()" />
    <input id="BTClose" type="button" value="?ر?豸" onclick="return BTClose_onclick()" />-->  
    <input id="BTUpload" type="button" value="&nbsp;上传签名&nbsp;" onclick="return BTUpload_onclick()" />
    <input id="BTResign" type="button" value="&nbsp;重新签名&nbsp;" onclick="return BTResign_onclick()" />
    <!--<input id="BTSave" type="button" value="??????" onclick="return BTSave_onclick()" />-->
  <div>

  <script language="javascript" type="text/javascript">

    var penwidth = 3;
    var obj;

    window.onload=function() {   
        hero();
        obj = document.getElementById("HWPenSign"); 
        obj.HWSetBkColor(0xE0F8E0);  
        obj.HWSetCtlFrame(2, 0x000000);
        res = obj.HWGetDevStatus();
        obj.HWFinalize();
        res = obj.HWInitialize();
        if (res != 0) {alert("签名板设备初始化失败!")}
        //alert(res);
    }

    window.onbeforeunload=function () {
        obj.HWFinalize();
        obj.HWClearPenSign();
    }

    function BTInit_onclick() {
        res = obj.HWInitialize();
        //alert(res);
    }

    function BTClose_onclick() {
        obj.HWFinalize();
    }

    function BTResign_onclick() {
        obj.HWClearPenSign();
    }

    function BTUpload_onclick() {
        var stream = obj.HWGetBase64Stream(2);
        //alert(typeof(stream))
        //alert(stream)
        $.ajax({
             url: "{{ host }}{% url 'check:sign_img' %}",
             type: "POST",
             crossDomain: true,
             dataType: "json",

             data: {sign: stream, task_id: {{ task_id }}},

             success: function (data) {
                 alert("签名提交成功!");
             },
             error: function (msg) {
                 if (msg != "OK") {
                    alert("签名提交成功!");
                 } else {
                    alert("错误: " + msg.statusText);
                 }
             }
             //base64转换看这里
             //https://blog.csdn.net/qq_34449006/article/details/84312550
        });
    }
       
    function BTSave_onclick() {
        obj.HWSetFilePath("e:\\sign.png"); 
        obj.HWSaveFile();
    }

    function signComplete() {
        BTUpload_onclick();
        BTClose_onclick();
        setTimeout(function(){ 
          BTInit_onclick(); 
        }, 3000);
    }

    function signRestart() {
        //alert("clear");
        BTResign_onclick();         
    }

  </script>

  <script type="text/javascript">
    function hero() {
        let herowidth = 640;
        let heroheight = 470;
        window.resizeTo(herowidth, heroheight);
    }
  </script>

  <style type="text/css">
    input {
        font-weight: bold;
        font-size: 16px;
    }
  </style>

</body>
</html>